import React, { useState, useEffect } from 'react'
import { Getcate } from '../../http/api'
import Header from "../../components/Header";
import Goods from "./components/Goods";
import qs from "querystring"

export default function List(props) {
    const [arr, setArr] = useState([])
    // 2.进来就发请求
    useEffect(() => {
        let params = qs.parse(props.location.search.slice(1));//{id:"2",type:1}
        Getcate({
            cateid: params.id,
            type: params.type
        }).then(res => {
            setArr(res.data.list.goodData ? res.data.list.goodData : [])
        })
    }, [])
    return (
        <div>
            {/* 头部组件 */}
            <Header title="分类列表" back></Header>
            {/* 商品列表 */}
            <Goods list={arr}></Goods>
        </div>
    )
}
